﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Model.Services;
using Domain.Model.Comparendos;
using Domain.Model.Repositories;
using Domain.Model.Aggregates;
using Domain.Model.Agentes;
using Domain.Model.Infractores;
using Domain.Model.Direcciones;
using Domain.Model.Infracciones;
using Domain.Model.SecretariasDeTransito;
using Domain.Model.Vehiculos;
using Domain.Model.Articulos;

namespace Domain.Model.Entidades.Comparendos
{
    public class ComparendoService: IComparendoService
    {
        /// Referencia al servicio de comparendos
        private ComparendoRepository comparendoRepository;


        //Constructor
        public ComparendoService(ComparendoRepository comparendoRepository)
        {
            if (comparendoRepository == null)
            {
                throw new ArgumentNullException("comparendoRepository");
            }
            this.comparendoRepository = comparendoRepository;
        }

        public Comparendo ComparendoFromId(string comparendoId)
        {
            return this.comparendoRepository.FromId(new ComparendoId(comparendoId));
        }

        public ComparendoId CreateComparendo(string numero, DateTime fecha, String tipoInfractor, String estado, String observacion, SecretariaDeTransitoId secretariaTransitoId, VehiculoId vehiculoId, InfraccionId infraccionId, AgenteId agenteId, InfractorId infractorId, Direccion direccion)
        {
            Comparendo newComparendo;
            newComparendo = ComparendoAggregate.CreateComparendo((ComparendoId)comparendoRepository.NextIdentity(), numero, fecha, tipoInfractor, estado, observacion,
                                                secretariaTransitoId, vehiculoId, infraccionId, agenteId, infractorId, direccion);

            this.comparendoRepository.Insert(newComparendo);
            return (ComparendoId)newComparendo.Identity;
        }


        public List<Comparendo> AllComparendos()
        {
            return this.comparendoRepository.All();
        }


        public void RemoveComparendo(ComparendoId comparendoId)
        {
            this.comparendoRepository.Remove(comparendoId);
        }


        public ComparendoId EditComparendo(ComparendoId comparendoId, string numero, DateTime fecha, String tipoInfractor, String estado, String observacion, SecretariaDeTransitoId secretariaTransitoId, VehiculoId vehiculoId, InfraccionId infraccionId, AgenteId agenteId, InfractorId infractorId, Direccion direccion)
        {
            Comparendo newComparendo;
            newComparendo = ComparendoAggregate.CreateComparendo(comparendoId, numero, fecha, tipoInfractor, estado, observacion,
                                                secretariaTransitoId, vehiculoId, infraccionId, agenteId, infractorId, direccion);
            this.comparendoRepository.Update(newComparendo);
            return (ComparendoId)newComparendo.Identity;
        }

        public Infraccion InfraccionFromId(string InfraccionId)
        {
            throw new NotImplementedException();
        }

        public List<Infraccion> AllInfracciones()
        {
            throw new NotImplementedException();
        }

        public void RemoveInfraccion(InfraccionId InfraccionId)
        {
            throw new NotImplementedException();
        }

        public InfraccionId CreateInfraccion(string codigo, string descripcion, int cantSMLVM, int esVigente, Articulos.Articulo articulo)
        {
            throw new NotImplementedException();
        }

        public InfraccionId EditInfraccion(InfraccionId InfraccionId, string codigo, string descripcion, int cantSMLVM, int esVigente, Articulos.Articulo articulo)
        {
            throw new NotImplementedException();
        }       

        public Articulo CreateArticulo(string nroArticulo, string ley, string descripcion)
        {
            throw new NotImplementedException();
        }

        public Direccion CreateDireccion(string domicilio, string municipio, string localidad, string codigoPostal)
        {
            throw new NotImplementedException();
        }

        public List<Comparendo> FromIdInfractor(InfractorId idInfractor)
        {
            return comparendoRepository.FromIdInfractor(idInfractor);
        }
    }
}
